<!--  Todo:实现一个方法，将传入对象的下划线命名方式全部换为驼峰式（考虑递归的场景） -->
  const obj = {
    my_name: 'jsliang',
    wo_de_jia: {
      zu_fang: 'guangzhou',
      jia: 'heyuan',
      zu_ji: 'maoming',
    },
  };

  /*
  转换为：
  {
    myName: 'jsliang',
    woDeJia: { jia: 'heyuan', zuFang: 'guangzhou', zuJi: 'maoming' },
  }
  */

  //判断是否Object
  const getType = arg => Object.prototype.toString.call(arg).slice(8, -1);
  //把名称改成递归
  const changeCamel = str => str.split('_').map((item, index) => index === 0 ? item : item.slice(0, 1).toUpperCase() + item.slice(1)).join('');

  const change = (obj) => {
    for (let i in obj) {
      if (obj.hasOwnProperty(i)) {
        //判断是否object 并 字段名带有_ 是对象改成驼峰并递归对象里面的内容
        if (getType(obj[i]) === 'Object' && i.includes('_')) {
          const now = changeCamel(i);
          obj[now] = obj[i];
          delete obj[i];
          change(obj[now]);
        } else if (getType(obj[i]) === 'Object') {
          //是对象，但不需要改成驼峰
          change(obj[i]);
        } else if (i.includes('_')) {
          // 不是对象，只改驼峰，不需要递归
          const now = changeCamel(i);
          obj[now] = obj[i];
          delete obj[i];
        }
      }
    }
    return obj;
  };

  console.log(change(obj));
